package com.cskaoyan.service.wx_feedback;

import com.cskaoyan.bean.user.Feedback;
import com.cskaoyan.bean.user.User;
import com.cskaoyan.bean.wx_feedback.bo.WxFeedbackSubmitBo;
import com.cskaoyan.bean.wx_feedback.exception.AddFeedbackException;
import com.cskaoyan.bean.wx_resp.WxRespVo;
import com.cskaoyan.bean.wx_user.bo.WxRegisteredBo;
import com.cskaoyan.bean.wx_user.exception.AddUserException;
import com.cskaoyan.mapper.user.FeedbackMapper;
import com.cskaoyan.mapper.user.UserMapper;
import com.cskaoyan.utils.EncryptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author liXiaoFei
 * @date 2021/10/21 19:55
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService{

    @Autowired
    FeedbackMapper feedbackMapper;



    @Override
    public void addFeedback(WxFeedbackSubmitBo wxFeedbackSubmitBo, User user) throws AddFeedbackException {
        Feedback feedback = new Feedback();
        feedback.setUserId(user.getId());
        feedback.setUsername(user.getUsername());
        feedback.setMobile(wxFeedbackSubmitBo.getMobile());
        feedback.setFeedType(wxFeedbackSubmitBo.getFeedType());
        feedback.setContent(wxFeedbackSubmitBo.getContent());
        feedback.setStatus(1);
        feedback.setHasPicture(wxFeedbackSubmitBo.getHasPicture());
        if (wxFeedbackSubmitBo.getHasPicture()){
            feedback.setPicUrls(wxFeedbackSubmitBo.getPicUrls().get(0));
        }
        feedback.setAddTime(new Date(System.currentTimeMillis()));
        feedback.setUpdateTime(new Date(System.currentTimeMillis()));
        feedback.setDeleted(false);
        int code = feedbackMapper.insert(feedback);
        if (code == 0) throw new AddFeedbackException();
    }




}
